// -*- mode: groovy -*-
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.
//
//This is a Jenkinsfile for the broken link checker test.

node('utility') {
  // Loading the utilities requires a node context unfortunately
  checkout scm
  utils = load('ci/Jenkinsfile_utils.groovy')
}
utils.assign_node_labels(utility: 'utility', linux_cpu: 'mxnetlinux-cpu')

utils.main_wrapper(
core_logic: {
  stage('BLC'){
    parallel 'BrokenLinkChecker: CPU': {
      node(NODE_LINUX_CPU) {
        ws('workspace/brokenLinkChecker') {
          timeout(time: 60, unit: 'MINUTES') {
            try {
              utils.init_git()
              utils.docker_run('ubuntu_blc', 'broken_link_checker', false)
            } catch(Exception ex) {
              sh "echo Broken Link Checker failed with exception - " + ex.toString()
            }
          }
        }
      }
    }
  }
}
,
failure_handler:
{
  if (currentBuild.result == "FAILURE") {
    emailext body: '''https://mxnet.apache.org  broken link test summary:
          |
          |Please view the logs at ${BUILD_URL}
          |
          |${BUILD_LOG_EXCERPT, start="START - Broken links summary", end="END - Broken links summary"}''',
      replyTo: '${EMAIL}', subject: '[BROKEN LINK CHECKER FAILED] Run ${BUILD_NUMBER}', to: '${EMAIL}'
  }
}
)
